package com.mall.web.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mall.common.dao.MongoDBManager;
import com.mall.untils.LoggerUtil;

@Controller
public class TestData {

	@SuppressWarnings("unchecked")
	@RequestMapping("/test_hadoop")
	@ResponseBody
	public String testHadoop(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		
		String json_data="{'t_id':1032,'t_time':'"+sdf.format(new Date())+"','bady_id':'2003'}";
		JSONObject fromObject = JSONObject.fromObject(json_data);
		Iterator<String> nameItr = fromObject.keys();
		String name;
		Map<String, Object> outMap = new HashMap<String, Object>();
		while (nameItr.hasNext()) {
			name = nameItr.next();
			outMap.put(name, fromObject.getString(name));
		}
		outMap.put("commint_time", new Date());
		outMap.put("data_type", "PC_CEPING_QUESTION");
		outMap.put("syst", "PC_CEPING_QUESTION");
		list.add(outMap);
		MongoDBManager.insertBatch("pc_collection", list);
		LoggerUtil.getLogger(TestData.class);
		return "test_hadoop";
	}
}
